package com.team.sion.controller;

import com.team.sion.common.FatalMessage;
import com.team.sion.common.SuccessMessage;
import com.team.sion.pojo.Collect;
import com.team.sion.pojo.Messages;
import com.team.sion.service.CollectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/collection")
public class CollectController {
    @Autowired
    private CollectService collectService;

    @RequestMapping("/detail")
    public Object getCollectionOfUser(Integer userId){
        List<Collect> list = collectService.getByUserId(userId);
        return new SuccessMessage<List<Collect>>("collect",list).getMessage();
    }

    @RequestMapping("/add")
    public Object setCollection(Collect collection){
        if(collection.getSongId()!=null){
            if(collection.getType().equals("1")){
                collection.setSonglistId(collection.getSongId());
                collection.setSongId(null);
            }
            collectService.addCollect(collection);
            return new SuccessMessage<Boolean>("add",true).getMessage();
        }return null;
    }

    @RequestMapping("/delete")
    public Object deleteCollection(Integer userId, Integer songId){
        collectService.deleteCollect(userId,songId);
        return new SuccessMessage<Boolean>("delete",false).getMessage();
    }

    @RequestMapping("/status")
    public Object isCollection(Collect collect){
        Boolean flag = collectService.getStatus(collect);
        if(flag){
            return new SuccessMessage<Boolean>("success",true).getMessage();
        }
        return new SuccessMessage<Boolean>("failed",false).getMessage();
    }

    @RequestMapping("/deleteList")
    public Object deleteListCollection(Integer userId, Integer songlistId){
        collectService.deleteListCollect(userId,songlistId);
        return new SuccessMessage<Boolean>("delete",false).getMessage();
    }

    @RequestMapping("/deleteLists")
    public Object deleteList(Integer userId,Integer songListId){
        Boolean flag = collectService.deleteList(userId, songListId);
        return new SuccessMessage<Boolean>("deleteList",false).getMessage();
    }
}
